package com.xbai.bean.definition;

import com.xbai.domain.User;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author jxbai
 * @desc Bean 别名示例
 * @date 2021/1/26
 */
public class BeanAliasDemo {

    public static void main(String[] args) {
        // 配置 XML 配置文件
        // 启动 Spring 应用上下文
        BeanFactory beanFactory = new ClassPathXmlApplicationContext("classpath:/META-INF/bean-definitions-context.xml");
        User user = beanFactory.getBean("user", User.class);
        // 通过别名 xbai-user 获取曾用名 user 的 bean
        User xbaiUser = beanFactory.getBean("xbai-user", User.class);
        System.out.println("xbai-user 是否与 user Bean 相同：" + (user == xbaiUser));
    }
}
